package com.seawaterbt.springbootshiro.exception;

import org.apache.shiro.authz.AuthorizationException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.servlet.http.HttpServletRequest;

@ControllerAdvice
public class GlobalDefultExceptionHandler {

    @ExceptionHandler(Exception.class)
    public String defultExceptionHandler(HttpServletRequest request,Exception e){
        request.setAttribute("error",e.getMessage());
        return "error";
    }

    @ExceptionHandler(AuthorizationException.class)
    public String authorizationExceptionHandler(HttpServletRequest request,AuthorizationException e){
        request.setAttribute("error",e.getMessage());
        return "403";
    }
}
